package br.edu.ufersa.scrumgame.mbean;

import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import br.edu.ufersa.scrumgame.facade.PapelFacade;
import br.edu.ufersa.scrumgame.modelo.Papel;

@ManagedBean
@SessionScoped
public class PapelMBean {

	@EJB
	private PapelFacade papelFacade;
	
	private Papel papel = new Papel();
	
	private List<Papel> papeis;
	
	private List<Papel> papeisFiltro;
	
	private String acao;
	
	public List<Papel> getPapeisFiltro() {
		return papeisFiltro;
	}

	public void setPapeisFiltro(List<Papel> papeisFiltro) {
		this.papeisFiltro = papeisFiltro;
	}

	public Papel getPapel() {
		if( papel == null ) {
			papel = new Papel();
		}
		return papel;
	}

	public void setPapel(Papel papel) {
		this.papel = papel;
	}
	
	public List<Papel> getPapeis() {
		papeis = papelFacade.findAll();
		return papeis;
	}

	public String getAcao() {
		return acao;
	}

	public void novo() {
		acao = "novo";
		papel = new Papel();
	}
	
	public void salvar() {
		if(acao == "novo") {
			papel.setId(0);
			papelFacade.save(papel);
		} if(acao == "editar") {
			papelFacade.update(papel);
		}
	}
	
	public void editar() {
		acao = "editar";
	}
	
	public void deletar() {
		papelFacade.delete(papel);
	}

}
